package com.yisoo.ubag.iot.config;


import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.profile.IClientProfile;
import com.yisoo.ubag.iot.aliyun.util.LogUtil;
import lombok.Data;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Properties;

//@Configuration
//@Data
public class AliClientConfig {

//    mqtt.user.accessKeyID = LTAI4GJsxqB4enkdqv5VievY
//# sk
//    mqtt.user.accessKeySecret =NVhn0K3qBRsiC2KuQDnQtlnxI4Lacv
//# 要访问的iot的regionId 目前支持的 cn-shanghai(华东2)、ap-southeast-1（新加坡） 、us-west-1（美西）
//    mqtt.iot.regionId = cn-shanghai
//#iot套件对应的产品code 保持不变即可
//    mqtt.iot.productCode = Iot
//#Iot api的服务地址 跟regionId对应 这是华东2的
//    mqtt.iot.domain = iot.cn-shanghai.aliyuncs.com
//#Iot api 的版本
//    mqtt.iot.version = 2018-01-20
    @Value("${mqtt.user.accessKeyID}")
    private  String accessKeyID;
    @Value("${mqtt.user.accessKeySecret}")
    private  String accessKeySecret;
    @Value("${mqtt.iot.regionId}")
    private  String regionId;
    @Value("${mqtt.iot.domain}")
    private  String domain;
    @Value("${mqtt.iot.version}")
    private  String version;
    @Value("${mqtt.iot.productCode}")
    private  String productCode;


    @Bean
    public DefaultAcsClient getClient(){
//        IClientProfile profile = DefaultProfile.getProfile("cn-shanghai", accessKey, accessSecret);
//        return new DefaultAcsClient(profile);
        DefaultAcsClient client = null;
        try {
            IClientProfile profile = DefaultProfile.getProfile(regionId, accessKeyID, accessKeySecret);
            DefaultProfile.addEndpoint(regionId, regionId, productCode,
                    domain);
            // 初始化client
            client = new DefaultAcsClient(profile);

        } catch (Exception e) {
            LogUtil.print("初始化client失败！exception:" + e.getMessage());
        }
        return client;

    }

}
